package com.bjc.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.net.Socket;

/**
 * @program: nettypro
 * @description:
 * @author: bjc
 * @create: 2021-09-05 20:47
 */
public class OldIOClient {

    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("127.0.0.1", 7001);
        String fileName = "D:\\iotest_delete\\seata-server-0.9.0.zip";
        FileInputStream inputStream = new FileInputStream(fileName);
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] buffer = new byte[4096];
        long readCount;
        long total = 0L;
        long startTime = System.currentTimeMillis();
        while ((readCount=inputStream.read(buffer))>=0){
            total+=readCount;
            dataOutputStream.write(buffer);
        }
        long endTime = System.currentTimeMillis();
        System.out.println("发送总字节数："+total+"，耗时："+(endTime-startTime));
        dataOutputStream.close();
        socket.close();
        inputStream.close();
    }
}
